<extend name="layout/edit" />

<block name="HEADER">
   
</block>

<block name="CONTENT">
    <control:Form id="form"/>
</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
        var actionGrid,actionEdit,forms;
        
        //页面初始化
        ns.init=function(){
        	forms = layui.forms;
           	actionGrid=layui.grid.render("actionGrid","/system/navMng/config.xml");
            actionGrid.load([{"field":"nav_id","opera":"=","value":$.getRequest("oid")}]);
        }
        
        //保存
        ns.add=function(){
            form.save(2).then(function(res){
            	if(__mode==1){
            	    $.ajaxs("/admin/soft/nav/insertAction",{nav_id:res.data});
            	}
            	form.opener.grid.load();
            });
        }
        
        //新增动作点
        ns.addAction=function(){
        	if($.getRequest("mode")==1){
        		$.toast(0,"请先保存！");
        		return;
        	}
        	function successFn(){
        		$.ajaxs("/admin/soft/nav/getSerialNumber",{ nav_id: $.getRequest("oid") },function(res){
        		    actionEdit = forms.render("actionEdit","/system/pageMng/config.xml",{mode:1, oid:""});
        		    actionEdit.setValue("nav_id",$.getRequest("oid"));
        		    actionEdit.setValue("action_code",res.data);
        		});
        	}
        	function yesFn(index){
        		actionEdit.save(0).then(function(res){
	            	actionGrid.load();
	            	form.opener.grid.load();
	            	layer.close(index);
	            });
        	}
        	var html="<div id='actionEdit'></div>";
        	$.openModalDialog(html,"新增动作点",successFn,yesFn,["400px","250px"])
        }
        
        //编辑动作点
        ns.editAction=function(){
        	var selectedRow=actionGrid.getSelectedRows()[0];
        	function successFn(){
        		var param={mode:2,oid:selectedRow.action_id}
        		actionEdit = forms.render("actionEdit","/system/pageMng/config.xml",param);
        	}
        	function yesFn(index){
        		actionEdit.save(0).then(function(res){
	            	actionGrid.load();
	            	form.opener.grid.load();
	            	layer.close(index);
	            });
        	}
        	var html="<div id='actionEdit'></div>";
        	$.openModalDialog(html,"编辑动作点",successFn,yesFn,["400px","250px"])
        }
        
        //删除动作点
        ns.delAction=function(){
        	var selectedRows=actionGrid.getSelectedRows();
        	var is=true;
        	$.each(selectedRows, function(index,h) {
        		if(h.action_code=="00"){
        			is=false;
        		}
        	});
        	if(is){
        		actionGrid.deleteSelectRow(function(){
        			form.opener.grid.load();
        		});
        	}else{
        		$.toast(0,"查询动作点不能删除！");
        	}
        }
        
        return ns;
    }({}));
    
    //加载当前页面需要的控件和配置
    $(function(){  page.init();  });
   </script>
</block>



